package org.atovio.coolexam.common.config;

import org.atovio.coolexam.common.interceptor.JWTInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 配置JWT拦截器规则
 */
@Configuration
public class JWTInterceptorConfig extends WebMvcConfigurationSupport {

    @Bean
    public JWTInterceptor getJwtInterceptor() {
        return new JWTInterceptor();
    }

    /**
     * 配置token拦截器规则。看不懂
     *
     * @param registry 不懂
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        // 配置规则
        registry.addInterceptor(getJwtInterceptor()) // 配置JWTInterceptor
                .addPathPatterns("/**"); // /**表示拦截所有URL的请求
//                .excludePathPatterns("/**/login", "/**/register");
        super.addInterceptors(registry);
    }
}
